package cn.funeralobjects.youtube.dl.extension.model;

import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;

/**
 * @author FuneralObjects
 * Create date: 2020/4/7 2:32 AM
 */
@Data
@Accessors(chain = true)
public class DownloadLog {
    /**
     * 进度百分比
     */
    private String percent;
    /**
     * 速度
     */
    private String speed;
    /**
     * 文件大小
     */
    private String size;
    /**
     * 剩余时间
     */
    private String eta;

    private static final String PREFIX = "[download]";

    public static DownloadLog serialize(String str){
        if(StringUtils.isEmpty(str) || !str.startsWith(PREFIX)){
            return null;
        }
        String[] data = str.split(" ");
        return new DownloadLog()
                .setPercent(data[1])
                .setSize(data[3])
                .setSpeed(data[5])
                .setEta(data[7]);
    }
}
